package edu.ynu.se.xiecheng.achitectureclass.service;

import edu.ynu.se.xiecheng.achitectureclass.common.service.LogicService;
import edu.ynu.se.xiecheng.achitectureclass.dao.BusinessDao;
import edu.ynu.se.xiecheng.achitectureclass.dao.ItemDao;
import edu.ynu.se.xiecheng.achitectureclass.dao.ShopDao;
import edu.ynu.se.xiecheng.achitectureclass.dao.ShopItemDao;
import edu.ynu.se.xiecheng.achitectureclass.entity.Business;
import edu.ynu.se.xiecheng.achitectureclass.entity.Item;
import edu.ynu.se.xiecheng.achitectureclass.entity.Shop;
import edu.ynu.se.xiecheng.achitectureclass.entity.ShopItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

@Service
public class BusinessService extends LogicService<BusinessDao, Business,Long> {
    public BusinessService(@Qualifier("businessDao") @Autowired BusinessDao dao) {
        super(dao);
    }
    @Autowired
    private ShopItemDao shopItemDao;

    public void createShopItem(Business business, Item item) {
        ShopItem shopItem = new ShopItem();
        shopItem.setBusiness(business);
        shopItem.setItem(item);
        shopItem.setOnSale(false); // 默认不上架

        shopItemDao.save(shopItem);
    }
    @Autowired
    private BusinessDao businessDao;
    public void createShop(Shop shop, Business business){

        businessDao.addShop(shop.getShopName(),shop.getAddress());
    }
    @Autowired
    private ItemDao itemDao;
    @Autowired
    private ShopDao shopDao;
    public void addItemToShop(Long businessId, Long itemId, Long shopId) {
        Business business = businessDao.findById(businessId).orElse(null);
        Item item =itemDao.findById(itemId).orElse(null);

        if (business != null && item != null) {
            Shop shop = businessDao.getShop(shopId); // 假设商家与店铺存在一对一关系
            shopDao.getItems(shopId).add(item); // 将商品添加到店铺中
        }
    }
}
